__author__ = 'zhenjiao.su'
# -*- coding: utf-8 -*-
from selenium.webdriver.support.wait import WebDriverWait
from excelrw import readxls
from time import sleep
from Other import login,loading
from Newwebdriver import Active
class confing(Active):
    def __init__(self,driver):
      Active.__init__(self,driver)
      self.driver=driver
      self.peoples=readxls("D:/pywebdriver/Pythonwebdriver/abc.xls")
      self.elreadc=readxls("D:/pywebdriver/Pythonwebdriver/element1.xls")
      self.confing_updatebutton=(self.elreadc(1,1),self.elreadc(1,2))
      self.confing_adulists=(self.elreadc(2,1),self.elreadc(2,2))
      self.confing_aduname=(self.elreadc(3,1),self.elreadc(3,2))
      self.confing_adutypelist=(self.elreadc(4,1),self.elreadc(4,2))
      self.confing_adutype=(self.elreadc(5,1),self.elreadc(5,2))
      self.confing_adutypeinfo=(self.elreadc(6,1),self.elreadc(6,2))
      self.confing_chillists=(self.elreadc(7,1),self.elreadc(7,2))
      self.confing_chilname=(self.elreadc(8,1),self.elreadc(8,2))
      self.confing_chiltypelist=(self.elreadc(9,1),self.elreadc(9,2))
      self.confing_chiltype=(self.elreadc(10,1),self.elreadc(10,2))
      self.confing_chiltypeinfo=(self.elreadc(11,1),self.elreadc(11,2))
      self.confing_chilsex=(self.elreadc(12,1),self.elreadc(12,2))
      self.confing_chilsexm=(self.elreadc(13,1),self.elreadc(13,2))
      self.confing_chilyear=(self.elreadc(15,1),self.elreadc(15,2))
      self.confing_chilmon=(self.elreadc(16,1),self.elreadc(16,2))
      self.confing_childay=(self.elreadc(17,1),self.elreadc(17,2))
      self.confing_email=(self.elreadc(24,1),self.elreadc(24,2))
      self.confing_name=(self.elreadc(18,1),self.elreadc(18,2))
      self.confing_phone=(self.elreadc(19,1),self.elreadc(19,2))
      self.confing_loginbutton=(self.elreadc(23,1),self.elreadc(23,2))
      self.confing_button=(self.elreadc(22,1),self.elreadc(22,2))
      self.confing_loginfail=(self.elreadc(21,1),self.elreadc(22,2))
      self.confing_loadingstatu=(self.elreadc(25,1),self.elreadc(25,2))
      self.confing_changprice=(self.elreadc(26,1),self.elreadc(26.2))
    def confingexit(self):   #是否进入confing页
        try:
            WebDriverWait(self.driver,10).until(lambda a:a.find_element(*(self.confing_updatebutton)))
            return True
        except:
            return False
    def peopletrval(self):
        adultcount=len(self.find_elements(self.confing_adulists))
        for adults in range(1,adultcount+1):    #成人旅客信息填写
            adultname=self.peoples(adults,5)
            self.find_element(self.confing_aduname,adults).send_keys(adultname)       #成人姓名
            self.find_element(self.confing_adutypelist,adults).click()     #点击成人证件类型选择下拉框
            adultpapework=self.peoples(adults,6)
            for papeworks in range(1,9):      #证件类型选择
                adultpapename=self.find_element(self.confing_adutype,(adults,papeworks)).text
                if adultpapename==adultpapework:
                    self.find_element(self.confing_adutype,(adults,papeworks)).click()
            adultnumber=int(self.peoples(adults,7))
            self.find_element(self.confing_adutypeinfo,adults).send_keys(adultnumber)         #成人证件信息填写
        #开始判断是否有儿童，若有儿童，则填写儿童相关信息
        childexit=1
        try:
            childcount=len(self.find_elements(self.confing_chillists))
            childexit=2
        except:
            pass
        if childexit==2:
            for childs in range(1,childcount+1):
                childname=self.peoples(childs,8)
                self.find_element(self.confing_chilname,childs).send_keys(childname)
                self.find_element(self.confing_chiltypelist,childs).click()
                childwork=self.peoples(childs,9)
                for papeworks in range(1,9):      #证件类型选择
                    childpapework=self.find_element(self.confing_chiltype,(childs,papeworks)).text
                    if childwork==childpapework:
                        self.find_element(self.confing_chiltype,(childs,papeworks)).click()
                childnumber=str(int(self.peoples(childs,10)))
                if childwork==u"身份证":
                    self.find_element(self.confing_chiltypeinfo,childs).send_keys(childnumber)
                else:
                    self.find_element(self.confing_chiltypeinfo,childs).send_keys(childnumber)         #儿童证件信息填写
                    self.find_element(self.confing_chilsex,childs).click()   #儿童性别
                    self.find_element(self.confing_chilsexm,childs).click()  #儿童性别选择男
                    self.find_element(self.confing_chilyear,childs).send_keys(u"2011")
                    self.find_element(self.confing_chilmon,childs).send_keys(u"12")
                    self.find_element(self.confing_childay,childs).send_keys(u"13")
    def messagepeople(self):    ##联系信息填写
        messagename=self.peoples(1,11)
        self.find_element(self.confing_name).send_keys(messagename)
        messagephone=str(int(self.peoples(1,12)))
        self.find_element(self.confing_phone).send_keys(messagephone)
        useremail=self.peoples(1,13)
        self.find_element(self.confing_email).send_keys(useremail)
        try:    #判断是否登陆
            self.find_element(self.confing_loginbutton)
            loginexit=True
        except:
            loginexit=False
        if loginexit==True:
            self.find_element(self.confing_loginbutton).click()
            confinglogin=login(self.driver)
            confinglogin.logins()
    def messagesubmit(self):
        self.find_element(self.confing_button).click()
    def confingothenfail(self):  #判断3s内否出现提交失败，若出现则True,没则false
        try:
            WebDriverWait(self.driver,3).until(lambda a:a.find_element(*(self.confing_loginfail)))
            return True
        except:
            return False
    def confingloading(self,timeout=30):   #99%进入saveorder输出True,提交失败，留在原页面则输出False
        return loading(self.find_element(self.confing_loadingstatu),timeout=timeout)
    def confingdiffpay(self):
        try:
            self.find_element(self.confing_changprice)
            self.confingdifforder=self.find_element(self.confing_changprice).text
            return True
        except:
            return False










